package com.example.firstapp.KtLesson

import kotlin.concurrent.thread


// 1 基本
class MyThread1 : Thread() {
    override fun run() {
        for (i in 0..10 step 1){
            println(1)
            Thread.sleep(100)
        }
    }
}

// 2 Runnable接口降低耦合方式
class MyThread2 : Runnable {
    override fun run() {
        for (i in 0..10 step 1){
            println(2)
            Thread.sleep(100)
        }
    }
}
fun main() {
    MyThread1().start()
    val myThread1 = MyThread1()
    myThread1.start()

    val myThread2 = MyThread2()
    Thread(myThread2).start() //此处强制转换类型

// 3 lambda方式
    Thread {
        for (i in 0..10 step 1){
            println(3)
            Thread.sleep(100)
        }
    }.start()

// 4 kotlin提供
    thread {
        for (i in 0..10 step 1){
            println(4)
            Thread.sleep(100)
        }
    }
}